﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FrameworkManapro.BusinessModel;
using GMAC.ReportingSystem.Business.Entities;
using FrameworkManapro.WebUI;

namespace GMAC.ReportingSystem.Business.Components
{
    //--------------------------------------------------------------------------------------
    /// <summary>
    /// Ricardo Recaredo (24/03/2011)
    /// 
    /// Business Logic for HistoricRePurchase entities
    /// 
    /// </summary>
    //---------------------------------------------------------------------------------------

    public class HistoricRePurchaseComponent : IBusinessComponent<Entities.HistoricRePurchase>
    {
        #region Attributes

        private DataAccess.HistoricRePurchaseDataAccess dac;

        #endregion

        /////////////////////////////////////////////////////////////////

        #region Constructors

        public HistoricRePurchaseComponent()
        {
            dac = new DataAccess.HistoricRePurchaseDataAccess();
        }

        #endregion

        /////////////////////////////////////////////////////////////////

        #region IBusinessComponent Members

        public int Create(GMAC.ReportingSystem.Business.Entities.HistoricRePurchase entityToCreate)
        {
            if (Validate(entityToCreate))
            {
                var    result = dac.Insert(entityToCreate);
                return result;
            }
            return 0;
        }
       
        //-----------------------------------------------------------------------------------

        public int Delete(Entities.HistoricRePurchase entityToDelete)
        {
            if (entityToDelete.Equals(null))
            {
                throw new NullReferenceException();
            }

            return dac.Delete(entityToDelete);
        }

        //-----------------------------------------------------------------------------------

        public int Edit(GMAC.ReportingSystem.Business.Entities.HistoricRePurchase entityToEdit)
        {
            return Validate(entityToEdit) ? dac.Update(entityToEdit) : 0;
        }

        //------------------------------------------------------

        protected bool Validate(Entities.HistoricRePurchase historicRePurchase)
        {
            if (historicRePurchase == null)
            {
                throw new ArgumentNullException("InsuranceCompany", "The argument cannot be null.");
            }
            if (string.IsNullOrEmpty(historicRePurchase.LiquidationYear.ToString()))
            {
                throw new ArgumentNullException("Year", "The argument cannot be null.");
            }
            if (string.IsNullOrEmpty(historicRePurchase.PercentageApplied.ToString()))
            {
                throw new ArgumentNullException("PercentageApplied", "The argument cannot be null.");
            }
            if (string.IsNullOrEmpty(historicRePurchase.Repurchase.ToString()))
            {
                throw new ArgumentNullException("Repurchase", "The argument canno be null.");
            }
            if (string.IsNullOrEmpty(historicRePurchase.TotalBsCleared.ToString()))
            {
                throw new ArgumentNullException("TotalBsCleared", "The argument canno be null.");
            }
            if (string.IsNullOrEmpty(historicRePurchase.TotalCreditCleared.ToString()))
            {
                throw new ArgumentNullException("TotalCreditCleared", "The argument canno be null.");
            }

            return true;
        }

        //------------------------------------------------------

        public Entities.HistoricRePurchase GetDetails(object entityId)
        {
            return dac.Get(entityId);
        }

        #endregion

        /////////////////////////////////////////////////////////////////

        #region Public Methods

        public Entities.HistoricRePurchaseCollection GetList()
        {
            throw new NotImplementedException();
        }
 
        //-----------------------------------------------------

        public Years GetListOfAllYears()
        {
            return dac.GetListOfAllYears();
        }

        //-----------------------------------------------------

        public Years GetListOfAvailableYears()
        {
            return dac.GetListOfAvailableYears();
        }

        //------------------------------------------------------

        public Entities.HistoricRePurchaseCollection Search(int? year, PagingDetails paging)
        {
            return dac.Search(year, paging);
        }

        #endregion

    }
}
